<template>
  <div>
<h1>权益列表展示</h1>
    <table class="table table-bordered">
      <tbody>
      <tr style="background:aquamarine;">
        <td>编号</td>
        <td>名称</td>
        <td>状态</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in data.list" :key="i.Id">
        <td>{{i.Id}}</td>
        <td>{{i.ReighName}}</td>
        <td>{{i.ReState?"启用":"禁用"}}</td>
        <td>
          <input type="button" class="btn btn-danger" value="删除" @click="del(i.Id)"/>
          <input type="button" class="btn btn-warning" value="修改" @click="upd(i.Id)"/>
          <input type="button" class="btn btn-warning" value="修改状态"  @click="sta(i.Id)"/>
        </td>
      </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import axios from "axios";
import moment from "moment";
import {useRoute,useRouter} from "vue-router";
const router = useRouter()
const route = useRoute()

onMounted(() => {
  getlist();
})

//接受数据
let data:any=reactive({

  list:[]
})

const getlist=()=>{
  axios({
    url:"https://localhost:7032/api/User/GetRight",
    method:"get",
  }).then(res=>{
    console.log(res)
   data.list=res.data
  })
}
const del=(id:any)=> {
  let f = confirm("确认删除")
  if (f) {
    axios({
      url: "https://localhost:7032/api/User/DelRight",
      method: "delete",
      params: {id: id}
    }).then(res => {
      console.log(res)
      if (res.data > 0) {
        alert("删除成功")
        getlist();
        return;
      } else {
        alert("删除失败")
        return;
      }
    })
  }
}
const sta=(id:any)=> {
  let f = confirm("确认修改")
  if (f) {
    axios({
      url: "https://localhost:7032/api/User/StateRight",
      method: "put",
      params: {id: id}
    }).then(res => {
      console.log(res)
      if (res.data > 0) {
        alert("修改成功")
        return;
      } else {
        alert("修改失败")
        return;
      }
    })
  }
}
const upd=(id:any)=>{
  router.push({
    path:"/regupdate",
    query:{id:id},
  })
}
</script>

<style scoped>

</style>